module.exports = {
    id: function() {
        return {
            "!primaryKey": true,
            "!valueType": "string",
            "!esType": "id"
        }
    },
    number_id: function() {
        return {
            "!primaryKey": true,
            "!columnType": "integer",
            "!valueType": "number",
            "!esType": "id"
        }
    },
    bool: function() {
        return {
            "!valueType": "boolean",
            "!defaultValue": false,
            "!esType": "boolean"
        }
    },
    boolean: function() {
        return {
            "!valueType": "boolean",
            "!defaultValue": false,
            "!esType": "boolean"
        }
    },
    strings: function() {
        return {
            "!columnType": "json",
            "!valueType": "array",
            "!operation": "overwrite",
            "!stringDelimiter": [",", " "],
            "!ignoreEmptyElement": true,
            "!autotrimString": true,
            "!arrayElement": {
                "!valueType": "string"
            },
            "!defaultValue": [],
            "!esType": "string"
        };
    },
    ids: function() {
        return {
            "!columnType": "json",
            "!valueType": "array",
            "!operation": "overwrite",
            "!stringDelimiter": [",", " "],
            "!ignoreEmptyElement": true,
            "!autotrimString": true,
            "!arrayElement": {
                "!valueType": "string"
            },
            "!defaultValue": [],
            "!esType": "id"
        };
    },
    number: function(defaultValue) {
        return {
            "!columnType": "integer",
            "!valueType": "number",
            "!defaultValue": defaultValue || 0,
            "!esType": "number"
        }
    },
    es_keyword: function(defaultValue, columnSize) {
        return {
            "!valueType": "string",
            "!columnSize": columnSize,
            "!defaultValue": defaultValue,
            "!esType": "custom",
            "!esCustom": {
                "type": "keyword"
            }
        }
    },
    es_keyword_noindex: function(defaultValue, columnSize) {
        return {
            "!valueType": "string",
            "!columnSize": columnSize,
            "!defaultValue": defaultValue,
            "!esType": "custom",
            "!esCustom": {
                "type": "keyword",
                "index": false
            }
        }
    },
    es_analyzer_email: function(defaultValue, columnSize) {
        return {
            "!valueType": "string",
            "!columnSize": columnSize,
            "!defaultValue": defaultValue,
            "!esType": "custom",
            "!esCustom": {
                "fields": {
                    "keyword": {
                        "ignore_above": 256,
                        "type": "keyword"
                    }
                },
                "type": "text",
                "analyzer": "index_email_analyzer",
                "search_analyzer": "search_email_analyzer"
            }
        }
    },
    es_geo_point: function(defaultValue, columnSize) {
        return {
            "!valueType": "string",
            "!columnSize": columnSize,
            "!defaultValue": defaultValue,
            "!esType": "custom",
            "!esCustom": {
                "type": "geo_point"
            }
        }
    },
    indexed_bool: function() {
        return {
            "!indexed": true,
            "!valueType": "boolean",
            "!defaultValue": false,
            "!esType": "boolean"
        }
    },
    indexed_date: function() {
        return {
            "!indexed": true,
            "!valueType": "number",
            "!columnType": "integer",
            "!defaultValue": 0,
            "!esType": "date"
        }
    },
    indexed_number: function(defaultValue) {
        return {
            "!indexed": true,
            "!columnType": "integer",
            "!valueType": "number",
            "!defaultValue": defaultValue || 0,
            "!esType": "number"
        }
    },
    indexed_string: function(defaultValue) {
        return {
            "!valueType": "string",
            "!indexed": true,
            "!defaultValue": defaultValue,
            "!esType": "string"
        }
    },
    labeled_string: function(label) {
        if (!label){
            throw new Error("Label not found");
        }
        return {
            "!valueType": "string",
            "!indexed": true,
            "!label": label,
        }
    },
    indexed_object: function(defaultValue) {
        return @.merge.simple({
            "!columnType": "json",
            "!valueType": "object",
            "!indexed": true,
            "!defaultValue": {},
            "!esType": "object"
        }, defaultValue)
    },
    indexed_objects: function(definition) {
        return {
            "!columnType": "json",
            "!valueType": "array",
            "!operation": "overwrite",
            "!stringDelimiter": [",", " "],
            "!ignoreEmptyElement": true,
            "!autotrimString": true,
            "!indexed": true,
            "!arrayElement": @.merge.simple({
                "!valueType": "object",
                "!defaultValue": {}
            }, definition),
            "!defaultValue": [],
            "!esType": "object"
        }
    },
    string: function(defaultValue, columnSize) {
        return {
            "!valueType": "string",
            "!columnSize": columnSize,
            "!defaultValue": defaultValue,
            "!esType": "string"
        }
    },
    object: function(defaultValue) {

        return @.merge.simple({
            "!columnType": "json",
            "!valueType": "object",
            "!columnSize": 65535,
            "!defaultValue": {},
            "!esType": "object"
        }, defaultValue)

    },
    objects: function(definition) {
        return {
            "!columnType": "json",
            "!valueType": "array",
            "!operation": "overwrite",
            "!stringDelimiter": [",", " "],
            "!ignoreEmptyElement": true,
            "!autotrimString": true,
            "!columnSize": 65535,
            "!arrayElement": @.merge.simple({
                "!valueType": "object",
                "!defaultValue": {}
            }, definition),
            "!defaultValue": [],
            "!esType": "object"
        }
    },
    asset: function(assetType, defaultValue) {
        return {
            "!valueType": "object",
            "!defaultValue": {},
            // asset_ids是一个4字节数字，以1字节.1字节.2字节 这种方式表示
            "asset_id": this.number(assetType),
            // amount是一个8字节整数
            "amount": this.number(defaultValue || 0),
            "!esType": "object"
        };
    },

    date: function() {
        return {
            "!valueType": "number",
            "!columnType": "integer",
            "!defaultValue": 0,
            "!esType": "date"
        }
    },
    double: function(defaultValue) {
        return {
            "!columnType": "real",
            "!valueType": "number",
            "!defaultValue": defaultValue || 0,
            "!esType": "double"
        }
    },
    price: function(assertType) {
        return {
            "!columnType": "json",
            "!valueType": "object",
            "!defaultValue": {
                "base": {
                    "asset_id": 0,
                    "amount": 0
                },
                "quote": {
                    "asset_id": 0,
                    "amount": 0
                }
            },
            base: this.asset(assertType),
            quote: this.asset(assertType),
            "!esType": "object"
        }
    },
    hidden: function() {
        return {
            "!hidden": true
        }
    },
    indexed: function() {
        return {
            "!indexed": true
        }
    }
}